package de.kraenksoft.android.cinemaExample.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Theater {
	
	Map<String, Movie> movies = new HashMap<String, Movie>();

	public List<Movie> getMovies() {
		if (movies == null)
			movies = new HashMap<String, Movie>();
		return new ArrayList<Movie>(movies.values());
	}

	public Screening getLastScreening() {
		Screening lastScreening = null;
		for (Movie movie : movies.values()) {
			for (Screening screening : movie.getScreenings()) {
				if (lastScreening == null
						|| screening.getStartTime().compareTo(
								lastScreening.getStartTime()) > 0) {
					lastScreening = screening;
				}
			}
		}
		return lastScreening;
	}

	public void add(Movie movie) {
		movies.put(movie.getName(), movie);
	}
	
	public boolean containsMovie(String name){
		return movies.containsKey(name);
	}
	
	public Movie get(String name){
		return movies.get(name);
	}

}